package com.fuhaiwei.domain.service.impl;

import java.util.List;

import com.fuhaiwei.domain.dao.UserDao;
import com.fuhaiwei.domain.model.User;
import com.fuhaiwei.domain.service.LoginService;
import com.fuhaiwei.domain.service.LoginResult;

public class LoginServiceImpl implements LoginService {

	private UserDao userDao;

	public LoginResult doLogin(String username, String password) {
		List find = userDao.findByUsername(username);
		if (find.size() == 0) {
			return LoginResult.USERNAME_NOTEXISTS;
		}
		if (find.size() == 1) {
			User user = (User) find.get(0);
			if (user.getPassword().equals(password)) {
				return LoginResult.LOGIN_SUCCESS;
			} else {
				return LoginResult.PASSWORD_WORNG;
			}
		}
		return LoginResult.DATABASE_ERROR;
	}

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

}